<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>门诊处方</title>
</head>
<body>
<style>
    .btn_a {
        background-image: linear-gradient(to right, #b8bcc4 0%, #757f9a 100%, #d7dde8 100%);
        text-align: center;
        text-transform: uppercase;
        transition: 0.5s;
        background-size: 200% auto;
        color: white;
        border-radius: 10px;
        border: white;
    }
    .btn_a:hover {
        background-position: right center; /* change the direction of the change here */
        color: #fff;
        text-decoration: none;
    }
    .btn_a:active{
        transform: scale(0.9);
    }
    .btn_b {
        background-image: linear-gradient(to right, #b8bcc4 0%, #757f9a 100%, #d7dde8 100%);
        text-align: center;
        text-transform: uppercase;
        transition: 0.5s;
        background-size: 200% auto;
        color: white;
        border-radius: 10px;
        border: white;
    }
    .btn_b:hover {
        background-position: right center; /* change the direction of the change here */
        color: #fff;
        text-decoration: none;
    }
    .btn_b:active{
        transform: scale(0.9);
    }
    .btn_c {
        background-image: linear-gradient(to right, #b8bcc4 0%, #757f9a 100%, #d7dde8 100%);
        text-align: center;
        text-transform: uppercase;
        transition: 0.5s;
        background-size: 200% auto;
        color: white;
        border-radius: 10px;
        border: white;
    }
    .btn_c:hover {
        background-position: right center; /* change the direction of the change here */
        color: #fff;
        text-decoration: none;
    }
    .btn_c:active{
        transform: scale(0.9);
    }
    .btn_d {
        background-image: linear-gradient(to right, #b8bcc4 0%, #757f9a 100%, #d7dde8 100%);
        text-align: center;
        text-transform: uppercase;
        transition: 0.5s;
        background-size: 200% auto;
        color: white;
        border-radius: 10px;
        border: white;
    }
    .btn_d:hover {
        background-position: right center; /* change the direction of the change here */
        color: #fff;
        text-decoration: none;
    }
    .btn_d:active{
        transform: scale(0.9);
    }
    div{
        border-radius: 3px;
        min-height: 18px;
    }
    body {
        background-color: #7291B5;
        font-family: Arial, sans-serif;
        margin: 0px;
        padding: 0px;
    }
    input {
        font-size:12px;font-family: 'Microsoft YaHei', '微软雅黑', MicrosoftJhengHei, '华文细黑', STHeiti, MingLiu;
        border:rgb(235, 235, 235) 1px solid;border-radius: 3px;padding: 5px 8px;outline: 0;
    }
    input:hover{ border: 1px solid #020202; }
    .div_total {
        background:linear-gradient(to top right, #ffffff,#EAEDEEFF);
        box-shadow: 0px 0px 10px 0px rgba(0,0,0,0.2);
        height:854px ;
        width:1473px ;
        position:absolute;
        margin-top: 20px;
        margin-left: 20px;
    }
    .div_top { background:linear-gradient(to top right, #ffffff,#EAEDEEFF);box-shadow: 0px 0px 10px 0px rgb(142, 144, 141);height:106px ;position:relative; margin: 10px;}
     .div_img { height:95px ;float:none;width:147px ;position:relative;left:10px;bottom:96px;margin:5px 0 5px 0; }
    .div_btn { position:relative;left:179px;top:5px;margin:5px 0 0 5px;height:95px ;width:1270px ; }
    .div_main { position:relative;top:2px;height:700px ;margin:22px auto 22px auto; }
    .div_main_left { background:linear-gradient(to top right, #ffffff,#EAEDEEFF);box-shadow: 0px 0px 10px 0px rgb(142, 144, 141);margin:10px 10px 10px 10px;position:relative;width:147px ;height:678px ; }
    .div_main_right { background:linear-gradient(to top right, #ffffff,#EAEDEEFF);box-shadow: 0px 0px 10px 0px rgb(142, 144, 141);margin:0px 10px 10px 10px;position:absolute;left:168px;top:0px;width:1282px ;height:678px ; }
     .img { height:94px ;width:117px ;position:relative;left:14px;margin:auto auto auto auto;background-size:cover;background-attachment:local;background-origin:border-box;}
     .tittle { position:relative;color:rgba(0, 0, 0, 1);font-style:normal;font-size:27px;text-shadow:0 0 0 rgba(0, 0, 0, 0);box-shadow:0 0 0 0 rgba(31, 31, 31, 31);opacity:1;transform:translate(0,19px);border:rgba(31, 31, 31, 1) solid 1px;text-align:center;letter-spacing:5px; }

     .div_name { position:relative;float: left;margin:10px 10px 10px 10px;width: 500px;height:50px ; }
     .txt_name { margin:0 10px 10px 25px;color:rgba(0, 0, 0, 1);font-style:normal;font-size:25px;font-weight:bolder;cursor:pointer;position:relative;top:10px; }
    .name { border:rgba(0, 0, 0, 1) solid 1px;margin:0 10px 10px 0;position:relative;height:24px ;width:300px ;font-style:italic;font-weight:normal;cursor:text;color:rgba(0, 0, 0, 1);font-size:25px;top:10px; }
    .age { border:rgba(0, 0, 0, 1) solid 1px;margin:0 10px 10px 0;width:300px ;height:24px ;position:relative;top:10px;color:rgba(0, 0, 0, 1);font-size:25px;font-weight:normal;cursor:text;font-style:italic; }
    .div_age { position:relative;float: left;margin:10px 10px 10px 10px;width: 500px;height:50px ; }
     .txt_age { margin:0 10px 10px 25px;color:rgba(0, 0, 0, 1);font-style:normal;font-size:25px;font-weight:bolder;cursor:pointer;position:relative;top:10px; }
     .div_sexy { position:relative;float: left;margin:10px 10px 10px 10px;width: 500px;height:50px ; }
     .txt_sexy { margin:0 10px 10px 25px;color:rgba(0, 0, 0, 1);font-style:normal;font-size:25px;font-weight:bolder;cursor:pointer;position:relative;top:10px; }
    .sexy { margin:0 10px 10px 0;position:relative;top:10px;color:rgba(0, 0, 0, 1);font-style:normal;font-size:25px;border:rgba(0, 0, 0, 1) solid 1px;font-weight:normal;cursor:pointer;height:32px ;width:60px ;text-align:center; }

     .div_department { position:relative;float: left;margin:10px 10px 10px 10px;width: 500px;height:50px ; }
     .txt_department { margin:0 10px 10px 25px;color:rgba(0, 0, 0, 1);font-style:normal;font-size:25px;font-weight:bolder;cursor:pointer;position:relative;top:10px; }
     .department{ margin:0 10px 10px 0;position:relative;top:10px;color:rgba(0, 0, 0, 1);font-style:normal;font-size:25px;border:rgba(0, 0, 0, 1) solid 1px;font-weight:normal;cursor:pointer;height:32px ;width:90px ;text-align:center; }

     .div_doctor { position:relative;float: left;margin:10px 10px 10px 10px;width: 500px;height:50px ; }
     .txt_doctor { margin:0 10px 10px 25px;color:rgba(0, 0, 0, 1);font-style:normal;font-size:25px;font-weight:bolder;cursor:pointer;position:relative;top:10px; }
     .doctor { margin:0 10px 10px 0;position:relative;top:10px;color:rgba(0, 0, 0, 1);font-style:normal;font-size:25px;border:rgba(0, 0, 0, 1) solid 1px;font-weight:normal;cursor:pointer;height:32px ;width:90px ;text-align:center; }

     .div_date { position:relative;float: left;margin:10px 10px 10px 10px;width: 500px;height:50px ; }
     .txt_date { margin:0 10px 10px 25px;color:rgba(0, 0, 0, 1);font-style:normal;font-size:25px;font-weight:bolder;cursor:pointer;position:relative;top:10px; }
     .date { border:rgba(0, 0, 0, 1) solid 1px;margin:0 10px 10px 0;width:300px ;height:24px ;position:relative;top:10px;color:rgba(0, 0, 0, 1);font-size:25px;font-weight:normal;cursor:text;font-style:italic; }

     .div_medicine { float: left;margin:10px 10px 10px 10px;position:relative;width: 1200px;height:300px ; }
     .txt_medicine { float: left;margin:0 10px 10px 25px;color:rgba(0, 0, 0, 1);font-style:normal;font-size:25px;font-weight:bolder;cursor:pointer;position:relative;top:10px; }
     .medicine { border:rgba(0, 0, 0, 1) solid 1px;margin:0 10px 10px 0;width:850px ;height:260px ;position:relative;top:10px;color:rgba(0, 0, 0, 1);font-size:25px;font-weight:normal;cursor:text;font-style:italic; }

    .btn_print {
        top:530px;right:250px;font-size:18px;
        position:relative;
        border: solid 1px black;
        background-image: linear-gradient(to right, #b8bcc4 0%, #757f9a 100%, #d7dde8 100%);
        text-transform: uppercase;
        transition: 0.5s;
        background-size: 200% auto;
        color: #000000;
        border-radius: 3px;
        border: black;
        cursor: pointer;}
    .btn_print:hover{
        background-position: right center; /* change the direction of the change here */
        color: #fff;
        text-decoration: none;
    }
    .btn_print:active{
        transform: scale(0.9);
    }
    .btn_create {
        top:530px;right:250px;font-size:18px;
        position:relative;
        border: solid 1px black;
        background-image: linear-gradient(to right, #b8bcc4 0%, #757f9a 100%, #d7dde8 100%);
        text-transform: uppercase;
        transition: 0.5s;
        background-size: 200% auto;
        color: #000000;
        border-radius: 3px;
        border: black;
        cursor: pointer;}
    .btn_create:hover{
        background-position: right center; /* change the direction of the change here */
        color: #fff;
        text-decoration: none;
    }
    .btn_create:active{
        transform: scale(0.9);
    }
    .btn_delete {
        top:530px;right:250px;font-size:18px;
        position:relative;
        border: solid 1px black;
        background-image: linear-gradient(to right, #b8bcc4 0%, #757f9a 100%, #d7dde8 100%);
        text-transform: uppercase;
        transition: 0.5s;
        background-size: 200% auto;
        color: #000000;
        border-radius: 3px;
        border: black;
        cursor: pointer;}
    .btn_delete:hover{
        background-position: right center; /* change the direction of the change here */
        color: #fff;
        text-decoration: none;
    }
    .btn_delete:active{
        transform: scale(0.9);
    }
    .btn_save {
        top:530px;right:250px;font-size:18px;
        position:relative;
        border: solid 1px black;
        background-image: linear-gradient(to right, #b8bcc4 0%, #757f9a 100%, #d7dde8 100%);
        text-transform: uppercase;
        transition: 0.5s;
        background-size: 200% auto;
        color: #000000;
        border-radius: 3px;
        border: black;
        cursor: pointer;}
    .btn_save:hover{
        background-position: right center; /* change the direction of the change here */
        color: #fff;
        text-decoration: none;
    }
    .btn_save:active{
        transform: scale(0.9);
    }

    .btn_b { position:relative;width:140px ;height:95px ;bottom:0px;font-style:normal;color:rgba(0, 0, 0, 1);font-size:32px;font-weight:bolder;text-align:center;text-decoration:underline;cursor:pointer; }
    .btn_c { width:140px ;height:95px ;position:relative;font-size:32px;font-style:normal;font-weight:bolder;text-align:center;text-decoration:underline;color:rgba(0, 0, 0, 1);cursor:pointer; }
    .btn_d { width:140px ;height:95px ;position:relative;color:rgba(0, 0, 0, 1);font-style:normal;font-size:32px;font-weight:bolder;text-align:center;text-decoration:underline;cursor:pointer; }
    .btn_a { width:140px ;height:95px ;position:relative;color:rgba(0, 0, 0, 1);font-size:32px;font-style:normal;font-weight:bolder;text-align:center;text-decoration:underline;cursor:pointer; }

    ul li{
        list-style-type: none;
        font-size: 20px;
    }
    a{
        color:rgba(0, 0, 0, 1);font-style:normal;font-size:15px;text-align:center;cursor:pointer;position:relative;top:20px;left: 10px;
    }

    .patient_list{
        position: relative;
        overflow-y: auto;
        height: 462px;
    }
    .patient_list div{
        text-align: center;
        font-size: 20px;
    }
    .div_user { float:right;position:relative;margin:10px 10px 10px 10px;width:414px ;height:70px ;top:2px;cursor:pointer; }
    .user {
        color:rgba(0, 0, 0, 1);font-style:normal;font-size:25px;text-align:center;cursor:pointer;position:relative;top:20px;
    }
    #search_name{
        width: 130px;
        border: solid 1px black;
        border-radius: 5px;
    }
    #search_name_btn{
        position: absolute;
        width: 148px;
        border: solid 1px black;
        font-size: 15px;
        background-image: linear-gradient(to right, #b8bcc4 0%, #757f9a 100%, #d7dde8 100%);
        text-transform: uppercase;
        transition: 0.5s;
        background-size: 200% auto;
        color: #000000;
        border-radius: 3px;
        border: black;
    }
    #search_name_btn:hover{
        background-position: right center; /* change the direction of the change here */
        color: #fff;
        text-decoration: none;
        border: solid 1px black;
    }
    #search_name_btn:active{
        transform: scale(0.9);
    }
    .whether_diagnosis_done{
        position: absolute;
        display: flex;

        width: 147px;
    }
    .whether-diagnostic{
        flex: 1;
        border: solid 1px;
        font-size: 15px;
        background-image: linear-gradient(to right, #b8bcc4 0%, #757f9a 100%, #d7dde8 100%);
        text-transform: uppercase;
        transition: 0.5s;
        background-size: 200% auto;
        color: #000000;
        border-radius: 3px;
    }
    .whether-diagnostic:hover{
        background-position: right center; /* change the direction of the change here */
        color: #fff;
        text-decoration: none;
        border: solid 1px black;
    }
    .whether-diagnostic:active{
        transform: scale(0.9);
    }
    .ul_patients{
        position: relative;
        top: 30px;
    }
</style>
<link href="/static/script/bootstrap_3.3.0/css/modal.css" type="text/css" rel="stylesheet" />
<link rel="stylesheet" href="https://www.58html.com/gui/css/font-awesome/css/font-awesome.css">
<div class="modal fade" id="createPrescriptionModal" role="dialog">
    <div class="modal-dialog" role="document" style="width: 50%;">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">
                    <span aria-hidden="true">×</span>
                </button>
                <h2 class="modal-title" id="myModalLabel1">新建处方</h2>
            </div>
            <div class="modal-body">

                <form id="createPrescriptionForm" class="form-horizontal" role="form">

                    <div class="form-group">
                        <label for="create-doctorName" class="col-sm-2 control-label">医生姓名</label>
                        <div class="col-sm-10" style="width: 150px;">
                            <input type="text" class="form-control" id="create-doctorName" readonly>
                        </div>
                    </div>
                    <div class="form-group" style="float:right;">
                        <label for="create-patientName" class="col-sm-2 control-label">病人姓名</label>
                        <div class="col-sm-10" style="width: 150px;">
                            <input type="text" class="form-control" id="create-patientName" readonly>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="create-department" class="col-sm-2 control-label">科室</label>
                        <div class="col-sm-10" style="width: 150px;">
                            <input type="text" class="form-control" id="create-department" readonly/>
                        </div>
                    </div>
                    <div class="form-group" style="float:right;">
                        <label for="create-sexy" class="col-sm-2 control-label">性别</label>
                        <div class="col-sm-10" style="width: 150px;">
                            <input type="text" class="form-control" id="create-sexy" readonly>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="create-datetime" class="col-sm-2 control-label">日期</label>
                        <div class="col-sm-10" style="width: 150px;">
                            <input type="date" class="form-control" rows="3" id="create-datetime"/>
                        </div>
                    </div>
                    <div id="core_content">
                        <div class="form-group">
                            <label for="create-prescription" class="col-sm-2 control-label">处方<span style="font-size: 15px; color: red;">*</span></label>
                            <div class="col-sm-10" style="width: 267%;">
                                <textarea class="form-control" rows="3" id="create-prescription"></textarea>
                            </div>
                        </div>
                    </div>

                </form>

            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" id="savePrescriptionBtn">保存</button>
            </div>
        </div>
    </div>
</div>
<div id="lyrow">
    <div class="div_total">
        <div class="div_top">
            <div class="div_btn">
                <div class="div_user">
                    <span class="user" th:text="${doctor.getDoctorName()}"></span>
                    <a href="/changePassword">修改密码</a>
                    <a href="/logout">退出登录</a>
                    <a href="/changeAccount">更改账户</a>
                </div>

                <input type="button" name="button" value="门诊诊断" class="btn_a">
                <input type="button" name="button" value="门诊处方" class="btn_b">
                <input type="button" name="button" value="申请单" class="btn_c">
                <input type="button" name="button" value="门诊历史" class="btn_d">
            </div>
            <div class="div_img">
                <img src="http://localhost:8080/static/img/图标.png" class="img">
            </div>
        </div>
        <div class="div_main">
            <div class="div_main_left">
                <h1 class="tittle">病人列表</h1>
                <div class="patient_list">
                    <div class="whether_diagnosis_done">
                        <input type="button" class="whether-diagnostic" id="diagnosis_done" value="已诊">
                        <input type="button" class="whether-diagnostic" id="no_diagnosis_done" value="未诊">
                    </div>
                    <ul class="ul_patients"></ul>
                </div>
                <input type="text" name="search_name" id="search_name" value="">
                <input type="button" id="search_name_btn" value="查询"/>
            </div>
            <div class="div_main_right">
                    <div class="div_name">
                        <span class="txt_name">姓名:</span>
                        <input type="text" name="input" class="name" placeholder="请输入姓名" value="" readonly></div>
                    <div class="div_age">
                        <span class="txt_age">年龄:</span>
                        <input type="text" name="input" class="age" value="" placeholder="请输入年龄" readonly></div>
                    <div class="div_sexy">
                        <span class="txt_sexy">性别:</span>
                        <select name="select" class="sexy">
                            <option value="1">男</option>
                            <option value="0">女</option>
                        </select>
                    </div>
                    <div class="div_department">
                        <span class="txt_department">科室:</span>
                        <select name="select" class="department">
                            <option value=""></option>
                        </select>
                    </div>
                    <div class="div_date">
                        <span class="txt_date">日期:</span>
                        <input type="date" name="input" class="date" value="">
                    </div>
                    <div class="div_doctor">
                        <span class="txt_doctor">医生:</span>
                        <select name="select" class="doctor">
                            <option th:value="${doctor.getDoctorId()}" th:text="${doctor.getDoctorName()}"></option>
                        </select>
                    </div>
                    <div class="div_medicine">
                        <span class="txt_medicine">处方:</span>
                        <textarea name="textarea" class="medicine" placeholder="请输入详细处方"></textarea>
                    </div>
                    <input type="submit" name="button" value="打印" class="btn_print">
                    <input type="submit" name="button" value="删除" class="btn_delete">
                    <input type="submit" name="button" value="保存" class="btn_save">
                    <input type="submit" name="button" value="新建" class="btn_create">
            </div>
        </div>
    </div>
</div>
<div class="print-view" style="position:absolute;width:0px;height:0px;left:-500px;top:-500px;">
    <div class="container">
        <div class="header">
            <img src="/static/img/图标.png" class="img">
            <h2 style="position: absolute;top: 130px;">病人处方</h2>
            <h3 style="top: 160px;position: absolute">------------------------------------------------------------------------------------------------------------------</h3>
        </div>

        <div class="section" style="margin-top: 50px">

            <h2>患者信息</h2>
            <table class="table" id="tb_patientInformation">
                <tr>
                    <th>姓名</th>
                    <td id="td_patient_name"></td>
                </tr>
                <tr>
                    <th>性别</th>
                    <td id="td_sexy"></td>
                </tr>
                <tr>
                    <th>年龄</th>
                    <td id="td_age"></td>
                </tr>

                <tr>
                    <th>就诊日期</th>
                    <td id="td_date"></td>
                </tr>
                <tr>
                    <th>医生</th>
                    <td id="td_doctor_name"></td>
                </tr>
                <tr>
                    <th>科室</th>
                    <td id="td_department"></td>
                </tr>
            </table>
        </div>
        <div class="section">
            <h2>处方信息</h2>
            <table class="table" id="tb_medicalInformation">
                <tr>
                    <th>症状</th>
                    <td id="td_prescription"></td>
                </tr>
            </table>
        </div>
    </div>
    <footer style="text-align: center;position: relative;top: 300px">
        <p>版权所有 © xdy 打印预览示例</p>
        <h3 style="position: relative">------------------------------------------------------------------------------------------------------------------</h3>
    </footer>
</div>
</body>
<script  src="/static/script/jquery-1.11.1-min.js"></script>
<script  src="/static/script/bootstrap_3.3.0/js/bootstrap.min.js"></script>
<script type="text/javascript">
    $(function (){
        $(".btn_a").css({color:"#000000"})
        $(".btn_b").css({color:"#f1f1f1"})
        $(".btn_c").css({color:"#000000"})
        $(".btn_d").css({color:"#000000"})
    })
    var patient_id="";
    /**
     * 状态变量，在查询病人时判断当前处于是否完成诊断的列表下 false:处于为诊断; true:处于已经诊断下
     * @type {boolean}
     */
    var whether_diagnosis_flag=true;
    //加载已经诊断病人列表
    function list_diagnosis_done_patients(){
        $.ajax({
            url:'/main/diagnosis_done_patient_list',
            type:'post',
            dataType:'json',
            success:function (data){
                var html="";
                $.each(data.patients,function (index,obj){
                    html+="<li value=\""+obj.patientId+"\"onclick='getPatientPrescription($(this))'>"+obj.patientName+"</li>"
                });
                $(".ul_patients").html(html);
            }
        })
    }
    //加载未诊断病人列表
    function list_no_diagnosis_done_patients(){
        $.ajax({
            url:'/main/no_diagnosis_done_patient_list',
            type:'post',
            dataType:'json',
            success:function (data){
                var html="";
                $.each(data.patients,function (index,obj){
                    html+="<li value=\""+obj.patientId+"\"onclick='getPatientPrescription($(this))'>"+obj.patientName+"</li>"
                });
                $(".ul_patients").html(html);
            }
        })
    }
    //给未诊添加单击事件
    $("#no_diagnosis_done").click(function (){
        whether_diagnosis_flag=false;
        list_no_diagnosis_done_patients();
    })
    //给已诊添加单击事件
    $("#diagnosis_done").click(function (){
        whether_diagnosis_flag=true;
        list_diagnosis_done_patients();
    })
    //给门诊诊断按钮添加单击事件
    $(".btn_a").click(function (){
        window.location.href="/main/index";
    })
    //给申请单添加单击事件
    $(".btn_c").click(function (){
        window.location.href="/applicationForm/index";
    })
    //给门诊历史添加单击事件
    $(".btn_d").click(function (){
        window.location.href="/history/index";
    })
    //给查询按钮添加单击事件
    $("#search_name_btn").click(function (){
        var search_name=$("#search_name").val();
        $.ajax({
            url:'/main/queryBySearchName',
            data:{
                search_name:search_name,
                whether_diagnosis_flag:whether_diagnosis_flag
            },
            dataType:'json',
            type:'post',
            success:function (data){
                var html="";
                $.each(data.patients,function (index,obj){
                    html+="<li value=\""+obj.patientId+"\"onclick='getPatientPrescription($(this))'>"+obj.patientName+"</li>"
                });
                $(".ul_patients").html(html);
            }
        })
    })
    //查询框enter事件
    $("#search_name").keyup(function (event){
        if(event.keyCode===13){
            $("#search_name_btn").trigger("click");
        }
    })

    //单击病人显示处方信息
    function getPatientPrescription(obj){
        patient_id=$(obj).val();
        $("li").css({background: "#f1f1f1"});
        $(obj).css({background: "#a3a8b6",width:"60px",borderRadius:"5px"})
        $.ajax({
            url:'/prescription/patietn_prescription',
            data:{
                patient_id:patient_id
            },
            type:'post',
            dataType:'json',
            success:function (data){
                if(data.code=="0"){
                    $(".name").val(data.patient.patientName);
                    $(".age").val(data.patient.patientAge);
                    if(data.patient.patientSex=="男"){
                        $(".sexy option[value='1']").attr("selected",true);
                        $(".sexy option[value='0']").removeAttr("selected");
                    }else{
                        $(".sexy option[value='0']").attr("selected",true);
                        $(".sexy option[value='1']").removeAttr("selected");
                    }
                    $(".date").val("");
                    $(".medicine").val("");
                    alert(data.msg);
                }else{
                    $(".name").val(data.patient.patientName);
                    $(".age").val(data.patient.patientAge);
                    if(data.patient.patientSex=="男"){
                        $(".sexy option[value='1']").attr("selected",true);
                        $(".sexy option[value='0']").removeAttr("selected");
                    }else{
                        $(".sexy option[value='0']").attr("selected",true);
                        $(".sexy option[value='1']").removeAttr("selected");
                    }
                    $(".department option").val(data.department.departmentId);
                    $(".department option").text(data.department.departmentName);
                    $(".date").val(data.prescription.createTime);
                    $(".medicine").val(data.prescription.prescriptionContent);

                }
            }
        })
    }
    //给删除添加单击事件
    $(".btn_delete").click(function (){
        if(patient_id==""){
            alert("请先选择病人");
        }else{
            $.ajax({
                url:'/prescription/delete',
                data:{
                    patient_id:patient_id
                },
                type:'post',
                dataType:'json',
                success:function (data){
                    if(data.code=="1"){
                        alert(data.message);
                        $.ajax({
                            url:'/prescription/patietn_prescription',
                            data:{
                                patient_id:patient_id
                            },
                            type:'post',
                            dataType:'json',
                            success:function (data){
                                if(data.code=="0"){
                                    alert(data.msg);
                                }else{
                                    $(".name").val(data.patient.patientName);
                                    $(".age").val(data.patient.patientAge);
                                    if(data.patient.patientSex=="男"){
                                        $(".sexy option[value='1']").attr("selected",true);
                                        $(".sexy option[value='0']").removeAttr("selected");
                                    }else{
                                        $(".sexy option[value='0']").attr("selected",true);
                                        $(".sexy option[value='1']").removeAttr("selected");
                                    }
                                    $(".department option").val(data.department.departmentId);
                                    $(".department option").text(data.department.departmentName);
                                    $(".date").val(data.prescription.createTime);
                                    $(".medicine").val(data.prescription.prescriptionContent);
                                }
                            }
                        })
                    }else{
                        alert(data.message);
                    }
                }
            })
        }

    })
    //给保存添加单击事件
    $(".btn_save").click(function (){
        if(patient_id==""){
            alert("请先选择病人")
        }else{
            var medicine=$(".medicine").val();
            if(medicine==""){
                alert("请完善处方信息")
            }else{
                $.ajax({
                    url:'/prescription/savePrescription',
                    data:{
                        patient_id:patient_id,
                        medicine:medicine
                    },
                    type:'post',
                    dataType:'json',
                    success:function (data){
                        if(data.code=="1"){
                            alert(data.message);
                        }else{
                            alert(data.message);
                        }
                    }
                })
            }

        }
    })
    //给新建按钮添加单击事件
    $(".btn_create").click(function (){
        if(patient_id==""){
            alert("请选择病人")
        }else{
            var patient_name=$(".name").val();
            var doctor_name=$(".user").text();
            var patient_sexy=$(".sexy").val();
            var department=$(".department").text();
            var dateTime=$(".date").val();
            $("#createPrescriptionForm").get(0).reset();
            $("#createPrescriptionModal").modal("show");
            $("#create-doctorName").val(doctor_name);
            $("#create-department").val(department);
            $("#create-patientName").val(patient_name);
            $("#create-datetime").val(dateTime);
            if(patient_sexy=="1"){
                $("#create-sexy").val("男");
            }else{
                $("#create-sexy").val("女");
            }
        }
    })
    //给新建保存添加单击事件
    $("#savePrescriptionBtn").click(function (){
        var prescription=$("#create-prescription").val();
        if(prescription==""){
            alert("请完善处方")
        }else{
            $.ajax({
                url:"/prescription/createPrescription",
                type:'post',
                data:{
                    patient_id:patient_id,
                    prescription:prescription,
                },
                dataType:'json',
                success:function (data){
                    if(data.code=="1"){
                        $("#createPrescriptionModal").modal("hide");
                        $(".date").val(data.dateTime);
                        $(".medicine").val(data.prescription);
                    }else{
                        alert(data.msg);
                    }
                }
            })
        }

    })
    //给打印添加单击事件
    $(".btn_print").click(function (){
        if(patient_id==""){
            alert("请选择病人");
        }else if($(".medicine").val()!=""){
            $.ajax({
                url:'/prescription/print',
                data:{
                    patient_id:patient_id
                },
                type:'post',
                dataType:'json',
                success:function (data){
                    if(data.code==0){
                        alert(data.msg);
                    }else{
                        $(".print-preview").text("");
                        $("#td_patient_name").text(data.patientName);
                        $("#td_age").text(data.patientAge);
                        $("#td_sexy").text(data.patientSexy);
                        $("#td_date").text(data.date);
                        $("#td_doctor_name").text(data.doctorName);
                        $("#td_department").text(data.department);
                        $("#td_prescription").text(data.prescription);
                        if($("#td_prescription").text()==""){
                            alert("请完善处方信息并保存");
                            return;
                        }else{
                            var iframe=document.getElementById("print-iframe");
                            if(iframe==null){
                                var html=$(".print-view").html();
                                iframe = document.createElement('IFRAME');
                                var doc = null;
                                iframe.setAttribute("id", "print-iframe");
                                iframe.setAttribute('style', 'position:absolute;width:0px;height:0px;left:-500px;top:-500px;');
                                document.body.appendChild(iframe);
                                doc=iframe.contentWindow.document;
                                doc.write("<link href=\"/static/script/bootstrap_3.3.0/css/print_preview.css\" type=\"text/css\" rel=\"stylesheet\" />")
                                doc.write("<div>"+html+"</div>")
                                doc.close();
                                iframe.contentWindow.focus();
                            }
                            setTimeout(function(){ iframe.contentWindow.print();},50)
                            setTimeout(()=>{
                                document.body.removeChild(iframe);
                            },2000);
                        }
                    }
                }
            })
        }else {
            alert("请完善处方信息，并保存");
        }
    })
</script>
</html>